﻿// Module:             Games Programming
// Assignment1:        Platformer Game
// Add game feature:   
// Student Number:     S10095741D
// Student Name:       Ng Cheong Sian

//////////////////////////////////////////////////////////////////////////
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Game.UIScripts
{
    class UIController
    {
        private Panel _currentPanel;
        private readonly ContentManager _contentManager;
        private readonly MouseHandler _mouseCursor;

        private readonly SplashScreen _splashScreen;
        private readonly MainMenu _mainMenu;
        //private readonly LevelSelection _levelSelection;
        private readonly GameScreen _gameScreen;
        //private readonly LevelEditor _levelEditor;

        public string PlayLevel = "";

        private readonly Game1 _game1;

        public enum PanelType
        {
            SplashScreen = 1,
            MainMenu,
            LevelSelection,
            GameScreen,
            PauseMenu,
            CreditsScreen
        }

        public UIController(IServiceProvider serviceProvider, GraphicsDevice graphicsDevice, Game1 game)
        {
            _contentManager = new ContentManager(serviceProvider, "Content");
            _game1 = game;
            _mainMenu = new MainMenu(serviceProvider, graphicsDevice, _contentManager, this);
            //_levelSelection = new LevelSelection(serviceProvider, graphicsDevice, _contentManager, this);
            _gameScreen = new GameScreen(serviceProvider, graphicsDevice, _contentManager, this, "Level-1");
            _splashScreen = new SplashScreen(serviceProvider, graphicsDevice, _contentManager, this);
            //_levelEditor = new LevelEditor(serviceProvider, graphicsDevice, _contentManager, this);
            _mouseCursor = new MouseHandler(new Vector2(100, 0), _contentManager.Load<Texture2D>("Sprites/UI/Cursor"));
            _currentPanel = _splashScreen;
        }

        public ContentManager Content
        {
            get { return _contentManager; }
        }

        public void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState)
        {
            _currentPanel.Update(gameTime, keyboardState, mouseState);
            _mouseCursor.Update(mouseState);
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            _currentPanel.Draw(gameTime, spriteBatch);
            _mouseCursor.Draw(gameTime, spriteBatch);
            //DRAW SELECTED MENU
        }

        public void SetLevel(string level)
        {
            PlayLevel = level;
        }

        public void ChangePanel(PanelType newPanel,Panel previousScreen)
        {
            switch (newPanel)
            {
                case PanelType.SplashScreen:
                    //SplashScreen
                    _currentPanel = _splashScreen;
                    break;
                case PanelType.MainMenu:
                    _currentPanel = _mainMenu;
                    previousScreen.Reset();
                    
                    //MainMenu
                    break;
                /*case PanelType.LevelSelection:
                    //LevelSelection
                    _currentPanel = _levelSelection;
                    break;*/
                case PanelType.GameScreen:
                    //GameScreen
                    _gameScreen.Reset(PlayLevel);
                    _currentPanel = _gameScreen;
                    break;
                case PanelType.PauseMenu:
                    //PauseMenu
                    break;
                case PanelType.CreditsScreen:
                    //CreditsScreen
                    break;
            }
        }

        public void ExitGame()
        {
            _game1.Exit();
        }

    }
}
